#pragma once
#include"preCmpH.h"

BEGIN_NAMESPACE(ui_manager)
BEGIN_NAMESPACE(ui_events)
class UIEventManager;
BEGIN_NAMESPACE(ui_input)

enum{ACTION_NOACTION = 0, ACTION_DOWN, ACTION_UP}; // Posible actions
enum{KEY_LEFT = 1,KEY_RIGHT,KEY_UP,KEY_DOWN,
	KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_F11,KEY_F12,
	KEY_RETURN,KEY_BACKSPACE,KEY_SHIFT,KEY_ALT,KEY_CTRL,KEY_TAB,KEY_SPACE}; // Keys
enum{BUTTON_LEFT = 1,BUTTON_RIGHT,BUTTON_MIDDLE}; // Buttons

int GetMappedVirtualKey(int VK);

class UIInputManager;
typedef std::shared_ptr<UIInputManager> UIInputManagerPtr;

class UIInputManager
{
public:
	UIInputManager();
	~UIInputManager();
	static UIInputManager& getInstance();
	void StartUp(UIEventManager& manager);
	void ShutDown();
	void ClearInput();
	//-----------------------------------------------------------------------------
	// Set KeysState 
	//-----------------------------------------------------------------------------
	void ResetKeys();
	void SetKeyState(unsigned short key, unsigned short action);
	void SetKeysStateChanged(bool changed);
	//-----------------------------------------------------------------------------
	// Set MouseState
	//-----------------------------------------------------------------------------
	void ResetButtons();
	void SetMouseButtonState(unsigned short button, unsigned short action);
	void SetMouseCoordX(int x);
	void SetMouseCoordY(int y);
	void SetMouseCoordXY(int x,int y);
	void SetMouseAbsCoordX(int x);
	void SetMouseAbsCoordY(int y);
	void SetMouseAbsCoordXY(int x,int y);
	void SetButtonsStateChanged(bool changed);
	//-----------------------------------------------------------------------------
	// Get KeysState
	//-----------------------------------------------------------------------------
	short GetPrevKeyAction();
	short GetPrevKey();
	short GetLastKeyAction();
	short GetLastKey();
	short GetKeyState(unsigned short key);
	bool hasKeysStateChanged();
	//keysStruct* GetKeyboardKeysState();
	//-----------------------------------------------------------------------------
	// Get MouseState
	//-----------------------------------------------------------------------------
	short GetPrevMouseAction();
	short GetPrevMouseButton();
	short GetLastMouseAction();
	short GetLastMouseButton();
	short GetMouseButtonState(unsigned short button);
	int GetMouseCoordX();
	int GetMouseCoordY();
	void GetMouseCoordXY(int& x,int& y);
	int GetMouseAbsCoordX();
	int GetMouseAbsCoordY();
	void GetMouseAbsCoordXY(int& x,int& y);
	//mouseStruct* GetMouseState();
	bool hasButtonsStateChanged();

private:
	UIInputManager(const UIInputManager&);
	UIInputManager& operator= (const UIInputManager&);

	void _setKnoaction(short key);
	void _setKdown(short key);
	void _setKup(short key);
	void _setBnoaction(short button);
	void _setBdown(short button);
	void _setBup(short button);

	
	struct{
		short last_action_type;
		short last_action_key;

		short prev_action_type;
		short prev_action_key;
		//-----------------------------------------------------------------------------
		// A-Z Keys
		//-----------------------------------------------------------------------------
		short key_A;
		short key_B;
		short key_C;
		short key_D;
		short key_E;
		short key_F;
		short key_G;
		short key_H;
		short key_I;
		short key_J;
		short key_K;
		short key_L;
		short key_M;
		short key_N;
		short key_O;
		short key_P;
		short key_Q;
		short key_R;
		short key_S;
		short key_T;
		short key_U;
		short key_V;
		short key_W;
		short key_X;
		short key_Y;
		short key_Z;
		//-----------------------------------------------------------------------------
		// Arrow Keys
		//-----------------------------------------------------------------------------
		short key_LArrow;
		short key_RArrow;
		short key_DArrow;
		short key_UArrow;
		//-----------------------------------------------------------------------------
		// 0-9 Keys
		//-----------------------------------------------------------------------------
		short key_0;
		short key_1;
		short key_2;
		short key_3;
		short key_4;
		short key_5;
		short key_6;
		short key_7;
		short key_8;
		short key_9;
		//-----------------------------------------------------------------------------
		// F1-F12 keys
		//-----------------------------------------------------------------------------
		short key_F1;
		short key_F2;
		short key_F3;
		short key_F4;
		short key_F5;
		short key_F6;
		short key_F7;
		short key_F8;
		short key_F9;
		short key_F10;
		short key_F11;
		short key_F12;
		//-----------------------------------------------------------------------------
		// Other Keys
		//-----------------------------------------------------------------------------
		short key_Backspace;
		short key_Enter;
		short key_Shift;
		short key_Ctrl;
		short key_Alt;
		short key_Tab;
	} KeyboardInfo; // Keyboard info
	
	struct{
		short last_action_type;
		short last_action_button;

		short prev_action_type;
		short prev_action_button;
		//-----------------------------------------------------------------------------
		// X,Y Coordinates
		//-----------------------------------------------------------------------------
		int X;
		int Y;
		int AX;
		int AY;
		short Wheel;
		//-----------------------------------------------------------------------------
		// Buttons
		//-----------------------------------------------------------------------------
		short LButton;
		short RButton;
		short MButton;
	} MouseInfo; // Mouse info
	

	bool keyboard_state_changed;
	bool mouse_state_changed;
	bool keyboard_prev_set;
	bool mouse_prev_set;

};

END_NAMESPACE // UI inputs
END_NAMESPACE // UI events
END_NAMESPACE // UI manager